﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace sy4_10
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            listBox1.Items.Add("小王");
            listBox1.Items.Add("小李");
            listBox1.Items.Add("小陈");
            listBox1.Items.Add("小白");
            listBox1.Items.Add("小刘");
            listBox1.Items.Add("小徐");
        }
        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text == "") return; // 空内容不添加
            listBox1.Items.Add(textBox1.Text);
            textBox1.Text = ""; // 清空输入框
        }

        // “删除”按钮：移除ListBox选中项
        private void button2_Click(object sender, EventArgs e)
        {
            if (listBox1.SelectedIndex == -1) return; // 无选中项则返回
            listBox1.Items.RemoveAt(listBox1.SelectedIndex);
        }

        // “去抽奖”按钮：打开Form2并传递ListBox数据
        private void button3_Click(object sender, EventArgs e)
        {
            Form2 f2 = new Form2(listBox1); // 传递ListBox到Form2
            this.Hide(); // 隐藏Form1
            f2.ShowDialog(); // 模态显示Form2
            this.Show(); // Form2关闭后显示Form1
        }
    }
}
